package com.xiaomaoguai.redis.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xiaomaoguai.redis.entity.InterfaceCallLog;
import com.xiaomaoguai.redis.mapper.InterfaceCallLogMapper;
import com.xiaomaoguai.redis.service.InterfaceCallLogService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 接口调用日志 服务实现类
 * </p>
 *
 * @author WeiHui-Z
 * @since 2017-06-21
 */
@Service
@CacheConfig
public class InterfaceCallLogServiceImpl extends ServiceImpl<InterfaceCallLogMapper, InterfaceCallLog> implements InterfaceCallLogService {

    @Resource
    private InterfaceCallLogMapper interfaceCallLogMapper;

    /*
     *
     * @Cacheable 应用到读取数据的方法上，先从缓存中读取，如果没有再从DB获取数据，然后把数据添加到缓存中
     * unless 表示条件表达式成立的话不放入缓存
     */
    @Cacheable(value = "log", key = "#root.targetClass + #contractId", unless = "#result eq null")
    @Override
    public List<InterfaceCallLog> selectByContractId(String contractId) {
        return interfaceCallLogMapper.selectByContractId(contractId);
    }
}
